package com.newidea.facillty.restful;

import lombok.Getter;
import org.springframework.http.HttpStatus;

/**
 * Api结果状态
 */
public class ApiResultState {

    public static final int CODE_SUCCESS = 0;
    public static final String DESC_SUCCESS = "ok";

    /**
     * 状态码，0表示成功
     */
    @Getter
    private final int code;
    /**
     * 状态描述
     */
    @Getter
    private final String description;

    public ApiResultState() {
        this.code = CODE_SUCCESS;
        this.description = DESC_SUCCESS;
    }

    private ApiResultState(final int code, final String description) {
        this.code = code;
        this.description = description;
    }

    public static ApiResultState ok() {
        return new ApiResultState(CODE_SUCCESS, DESC_SUCCESS);
    }

    public static ApiResultState build(final int code, final String description) {
        return new ApiResultState(code, description);
    }

    public static ApiResultState build(final HttpStatus status, final String description) {
        return new ApiResultState(status.value(), description);
    }
}
